package com.hnyfkj.jyindustry.biz.item.controller;


import com.hnyfkj.jyindustry.biz.item.dto.BarItemInsertDto;
import com.hnyfkj.jyindustry.biz.item.dto.BarItemQueryDto;
import com.hnyfkj.jyindustry.biz.item.dto.BarItemUpdateDto;
import com.hnyfkj.jyindustry.biz.item.entity.BarItem;
import com.hnyfkj.jyindustry.biz.item.service.BarItemService;
import com.hnyfkj.jyindustry.biz.item.vo.BarItemVo;
import com.hnyfkj.jyindustry.common.dto.PageReturnDto;
import com.hnyfkj.jyindustry.common.dto.RespDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 理发店-------客户表
 *
 * @author zhangzhang
 * @email 15838129129@163.com
 * @date 2021-04-18 16:08:50
 */
@Controller
@RequestMapping("barItem")
public class BarItemController {
    @Autowired
    private BarItemService barItemService;



    /**
	 * 添加页面
	 */
    @GetMapping("/add")
    public String addPage() {
        return "barItem/barItem-add";
    }

    /**
     * 编辑页面
     */
    @GetMapping("/edit")
    public String editPage(@RequestParam("id") String id, Model model) {
        BarItem barItem = barItemService.getById(id);
        model.addAttribute("barItem", barItem);
        return "barItem/barItem-edit";
    }

    /**
     * 列表页面
     */
    @GetMapping("/listPage")
    public String listPage() {
        return "barItem/barItem-table";
    }




    /**
     * 列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public RespDto<PageReturnDto<BarItemVo>> list(@RequestBody BarItemQueryDto queryDto) {
        return RespDto.succResult(barItemService.queryPage(queryDto));
    }


    /**
     * 列表无分页
     */
    @RequestMapping("/listNoPage")
    @ResponseBody
    public RespDto<List<BarItem>> listNoPage() {
        return RespDto.succResult(barItemService.listNoPage());
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public RespDto<BarItem> info(@PathVariable("id") Integer id) {
        BarItem barItem = barItemService.getById(id);
        return RespDto.succResult(barItem);
    }

    /**
     * 保存
     */
    @RequestMapping("/insert")
    @ResponseBody
    public RespDto<String> insert(@RequestBody BarItemInsertDto barItemInsertDto) {
        barItemService.insert(barItemInsertDto);
        return RespDto.succ();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ResponseBody
    public RespDto<String> update(@RequestBody BarItemUpdateDto barItemUpdateDto) {
        barItemService.update(barItemUpdateDto);
        return RespDto.succ();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ResponseBody
    public RespDto<String> delete(String ids) {
        System.out.println(ids);
        barItemService.delete(ids);
        return RespDto.succ();
    }


}
